#include <string.h>
#include <stdio.h>
#include <unistd.h>
#include <fcntl.h>
#include <sys/stat.h>

int main(int argc, char **argv) {
  pid_t pid;
  int ret;
  pid = fork();

  if (pid > 0) {
    int fd;
    fd = open("./1.txt", O_WRONLY | O_CREAT);
    while (1) {
      ret = write(fd, "123456", 6);
      sleep(1);
    }
  }

  if (pid == 0) {
    sleep(1);
    int fd;
    fd = open("./1.txt", O_RDONLY);
    char buf[1024];
    while (1) {
      bzero(buf,1024);
      ret = read(fd,buf, 1024);
      printf("%s\n",buf);
      sleep(1);
    }
  }

  ret++;
  return 0;
}
